using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace ASPNETVN.PORTAL.Modules.CMS.Components
{
    public partial class Setup
    {
        public static DataSet GetItems(Guid moduleID, int categoryID, int categoryLevel, int itemNumber)
        {
            string spName = "[dbo].[p_CMS_Setup_GetItems]";
            if (categoryLevel == 2) spName = "[dbo].[p_CMS_Setup_GetItemsBy_CategoryLevel2]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);
            db.AddInParameter(dbCommand, "@CategoryID", SqlDbType.Int, categoryID);
            db.AddInParameter(dbCommand, "@ItemNumber", SqlDbType.Int, itemNumber);
            
            return db.ExecuteDataSet(dbCommand);
        }

        public static DataSet GetCategories(Guid moduleID)
        {
            const string spName = "[dbo].[p_CMS_Setup_GetCategories]";
            SqlDatabase db = (SqlDatabase)DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand)db.GetStoredProcCommand(spName);

            db.AddInParameter(dbCommand, "@ModuleID", SqlDbType.UniqueIdentifier, moduleID);

            return db.ExecuteDataSet(dbCommand);
        }
    }
}
